package com.atwork.wuhua.utils.GlideUtils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.ImageView;

import com.atwork.wuhua.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.request.RequestOptions;


/**
 * Created by Administrator on 2018/3/9 0009.
 */

public class GlideUtil {
    static RequestOptions options = new RequestOptions();

    //    加载普通图片
    @SuppressLint("CheckResult")
    public static void loadImage(Context context, String url, ImageView imageView) {
        options.centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.DATA)
                .placeholder(R.mipmap.icon_img_default);
        Glide.with(context)
                .load(url)
                .into(imageView);
    }

    //    加载自定义占位符
    public static void loadImagePlaceholder(Context context, ImageView imageView, int resouldId) {
        options.placeholder(resouldId).centerCrop();
        Glide.with(context)
                .asBitmap()
                .load("")
                .apply(options)
                .into(imageView);
    }

    //    加载自定义占位符
    public static void loadImagePlaceholder(Context context, String url, ImageView imageView, int resouldId) {
        options.placeholder(resouldId).centerCrop();
        Glide.with(context)
                .asBitmap()
                .load(url)
                .apply(options)
                .into(imageView);
    }

    public static void loadBannerImage(Context context, String url, ImageView imageView) {
        options.placeholder(R.mipmap.icon_img_default).centerCrop();
        Glide.with(context)
                .asBitmap()
                .load(url)
                .apply(options)
                .into(imageView);
    }

    //    加载圆角图片  4r
    @SuppressLint("CheckResult")
    public static void loadRoundImage(Context context, String url, ImageView imageView) {
        options.centerCrop()
                .placeholder(R.mipmap.icon_img_default)
                .skipMemoryCache(true)
                .transforms(new CenterCrop(), new GlideRoundTransform(context));
        Glide.with(context)
                .asBitmap()
                .load(url)
                .apply(options)
                .into(imageView);
    }

    //    加载圆型图片
    @SuppressLint("CheckResult")
    public static void loadCircleImg(Context context, String url, ImageView imageView) {
        options.centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.DATA)
                .placeholder(R.mipmap.icon_img_default)
                .circleCrop();

        Glide.with(context)
                .asBitmap()
                .load(url)
                .apply(options)
                .into(imageView);
    }

    //    加载头像
    @SuppressLint("CheckResult")
    public static void loadCircleThumb(Context context, String url, ImageView imageView) {
        options.centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.DATA)
//                .placeholder(R.mipmap.icon_avater_def)
                .circleCrop();

        Glide.with(context)
                .asBitmap()
                .load(url)
                .apply(options)
                .into(imageView);
    }

    //    加载大张图片
    public static void loadBigImg(Context context, String url, ImageView imageView) {
        options.placeholder(R.mipmap.icon_img_default).fitCenter()
                .diskCacheStrategy(DiskCacheStrategy.DATA)
        ;
//         .transforms(new CenterCrop(), new GlideRoundTransform(context))
        Glide.with(context)
                .load(url)
                .apply(options)
                .into(imageView);
    }
}
